package cube.net.socket;

/**
 * Socket连接监听池
 * 
 * @author abiao
 */
public class SocketListener extends SocketConnPool {

    /**
     * 创建连接
     */
    public void create(String ip, int port) {
        create(ip, port, false);
    }

    /**
     * 创建可以带有心跳的连接
     */
    public void create(String ip, int port, boolean autoReconn) {
        SocketConnect conn = new SocketConnectImpl(ip, port) {
            public void recv(SocketConnect conn, byte[] data) {
                SocketListener.this.recv(conn, data);
            }

            public void connectGain(SocketConnect conn) {
                SocketListener.this.connectGain(conn);
            }

            public void connectLost(SocketConnect conn) {
                SocketListener.this.connectLost(conn);
            }
        };
        super.add(conn);
        conn.setAutoReconnect(autoReconn);
    }

    /**
     * 接收数据
     */
    public void recv(SocketConnect conn, byte[] data) {
    }

    /**
     * 连接获得
     */
    public void connectGain(SocketConnect conn) {
    }

    /**
     * 连接丢失
     */
    public void connectLost(SocketConnect conn) {
    }
}
